import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Messenger {
	
	public static void main(String[] args) throws IOException {
		AtomicBroadcast atomic = new AtomicBroadcast();
//		Integer random = new Random().nextInt();
		Processor processor = new Processor(args[0]);
		for (int i = 1; i < args.length; i++) {
			System.out.println("Adding Neighbor: " + args[i]);
			processor.addLink(args[i]);
		}
		String sentence = "";
		while(!sentence.equals("end")) {
			BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
			sentence = inFromUser.readLine();
			Broadcast broadcast = new Broadcast(sentence);
			atomic.start(broadcast, processor);
		}
	}

}
